package oop.core.map;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import oop.core.area.AreaEffect;
import oop.core.area.DamageAreaEffect;
import oop.core.area.DeathAreaEffect;
import oop.core.area.HealAreaEffect;
import oop.core.area.LevelUpAreaEffect;
import oop.core.area.TeleportAreaEffect;
import oop.core.entity.Stats;
import oop.core.item.*;
import oop.core.visitors.InteractiveItemVisitable;


/**
 * This class includes static methods to parse map files
 * in order to instantiate a Map via files
 * @author Hoang Le
 */

public class MapParser
{
	
	/**
	 * parses a dot file to build the map for terrains. uses the character 
	 * g for grass, w for water, m for mountains, and i for impassible
	 * file should look like:
	 * ggggww
	 * ggggww
	 * gggggg
	 * mmgggg
	 * mmgggg
	 * 
	 * for all grass and water in top right and mountains in bottom left
	 * @param fileName
	 * @return
	 */
    public static Map<Location, Terrain> terrainParser (String fileName) {
		File file = new File(fileName);
		Map<Location, Terrain> myMap = new HashMap<Location, Terrain>();
		Terrain t = new Terrain("grass.png", MovementType.walk);
		try{
			Scanner sc = new Scanner(file);  
			boolean badFile = false;  
			boolean done = false;	// signifies done parsing
			int length = 0;
			char[] temp;
			
		
			int x = 0;
			int y = 0;
			temp = sc.nextLine().toCharArray();
			length = temp.length;
			while(!done && !badFile){
				// check that all lines are the same length
				if(temp.length != length)
					badFile = true;
				
				x = 0;	
				for (char c : temp){
					if(c == 'g'){ // grass
						t = new Terrain("grass", MovementType.walk);
					}	
					else if(c == 'm'){ // mountain
						t = new Terrain("mountain", MovementType.fly);
					}
					else if(c == 'w'){ // water
						t = new Terrain("water", MovementType.swim);
					}
					else if(c == 'i'){ // impassible
						t = new Terrain("black", MovementType.impassible);
					}
					else{ // if the file contains unrecognizable characters
						badFile = true;
					}
					myMap.put(new Location(x, y), t);
					x++;
				}
			
				if(!sc.hasNext()){
					done = true;
				}
				else
					temp = sc.nextLine().toCharArray();
				y++;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return myMap;
	}
    
    /**
     * This method is used to parse a text file and build the
     * hasMap of area effects. The file should use the form:
     * Damage 0 1 T 200 10
	 * Death 1 2 F 201 11
	 * Damage 2 3 F 202 12
	 * Heal 3 2 T 203 14
	 * Teleport 4 1 F 204 bestnameEver 5 9
	 * 
	 * The first word is the type of area effect (Damage,
	 * Death, Heal, Transport), the second and third are the
	 * x and y locations (respectively), next T or F is for isOn
	 * next integer is delay and the next integer is specific to
	 * each area effect (for damage:amount of damage, for Death:num
	 * of lives taken, for heal:num of health to add, for Teleport 
	 * the next three are the mapName(to travel to) and the x and y 
	 * position on that map)
	 *
     * @param fileName
     * @return
     */
    public static Map<Location, AreaEffect> areaEffectParser(String fileName) {
		Map<Location, AreaEffect> aFXMap = new HashMap<Location, AreaEffect>();
		File file = new File(fileName);
		boolean done = false;
		boolean badFile = false;
		try{
			Scanner sc = new Scanner(file);  
		
			while(!done){
		
				String type = sc.next();
				int xPos = sc.nextInt();
				int yPos = sc.nextInt();
			
				String isOnTemp = sc.next();
				boolean isOn = false;
				if(isOnTemp.equals("T") || isOnTemp.equals("t"))
					isOn = true;
				else if(isOnTemp.equals("F") || isOnTemp.equals("f"))
					isOn = false;
				long delay = sc.nextLong();

				int temp;
				int temp2;
				String tempS;
				if(type.equals("Damage") || type.equals("Death") || type.equals("Heal") || type.equals("Level")){
					temp = sc.nextInt();
					if(type.equals("Damage")){
						DamageAreaEffect damAE = new DamageAreaEffect(isOn, delay, temp);
						aFXMap.put(new Location(xPos, yPos), damAE);
					}
					else if(type.equals("Death")){
						DeathAreaEffect deathAE = new DeathAreaEffect(isOn, delay, temp);
						aFXMap.put(new Location(xPos, yPos), deathAE);
					}
					else if(type.equals("Heal")){
						HealAreaEffect healAE = new HealAreaEffect(isOn, delay, temp);
						aFXMap.put(new Location(xPos, yPos), healAE);
					}
					else if(type.equals("Level")){
						System.out.println("A LevelUp AE just got made!!!!!!");
						LevelUpAreaEffect levelUpAE = new LevelUpAreaEffect(isOn, delay, temp);
						aFXMap.put(new Location(xPos, yPos), levelUpAE);
					}
				}
				else if(type.equals("Teleport")){
					tempS = sc.next();
					temp = sc.nextInt();
					temp2 = sc.nextInt();
					TeleportAreaEffect tAE = new TeleportAreaEffect(isOn, delay, tempS, new Location(temp, temp2));
					aFXMap.put(new Location(xPos, yPos), tAE);
				}
				else 
					badFile = true;
		
				if(!sc.hasNext()){
					done = true;
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return aFXMap;
    }
    
    /**
     * decalParser parse similar to Vinny's way of AoE, but easier
     * Format for decalFile would be as followed
     * X Y imageName1
     * X Y imageName2
     * 0 1 imageName3
     * 20 20 imageName4
     * 
     * Hoang Le
     * @param fileName
     * @return
     */
    
    public static Map<Location, Decal> decalParser(String fileName)
    {
    	Map<Location,Decal> ret = null;
    	try
    	{
    		Scanner scanner = new Scanner(new File(fileName));
    		ret = new HashMap<Location,Decal>();
    		while(scanner.hasNextLine())
    		{
    			String decalString = scanner.nextLine();
    			String[] decalFields = decalString.split("\\s");
    			Location tempLocation = new Location(Integer.parseInt(decalFields[0]), Integer.parseInt(decalFields[1]));
    			Decal decal = new Decal(decalFields[2]);
    			ret.put(tempLocation, decal);
    			
    		}
        	
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
    	return ret;
    	

    }
    
    /**
     * Work similar as the decalParser
     * decalParser will have the file as the following format
     * 
     * X Y ObstacleItemName imageID
     * 10 20 Rock rock
     * 
     * Hoang Le
     * @param fileName
     * @return
     */
    public static Map<Location, ObstacleItem> obstacleItemParser(String fileName)
    {
    	Map<Location,ObstacleItem> ret = null;
    	try
    	{
    		Scanner scanner = new Scanner(new File(fileName));
    		ret = new HashMap<Location,ObstacleItem>();
    		while(scanner.hasNextLine())
    		{
    			String obstacleString = scanner.nextLine();
    			String[] obstacleFields = obstacleString.split("\\s");
    			Location tempLocation = new Location(Integer.parseInt(obstacleFields[0]), Integer.parseInt(obstacleFields[1]));
    			ObstacleItem obs = new ObstacleItem(obstacleFields[2], obstacleFields[3]);
    			ret.put(tempLocation, obs);
    			
    		}
        	
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
    	return ret;
    	

    }
    /**
     * File format for TakeableItemParser
     * ------
     * X Y QuestItem itemName imageID
     * X Y OneShotItem itemName imageID 
     * Exp Life HP MP STR AGI INT HAR MVMSPEED	 	// This is the Stat
     * X Y UsableItem itemName imageID price
     * Exp Life HP MP STR AGI INT HAR MVMSPEED    	
     * X Y EquippableItem itemName imageID price ITEMPOSITION EQUIPMENT_TYPE
     * Exp Life HP MP STR AGI INT HAR
     * occupationName1 occupationName2 ect..
     * 
     * @param fileName
     * @return
     */
    public static Map<Location, TakeableItem> takeableItemParser(String fileName)
    {
    	Map<Location, TakeableItem> ret = null;
    	try
    	{
    		Scanner scanner = new Scanner(new File(fileName));
    		ret = new HashMap<Location,TakeableItem>();
    		while(scanner.hasNextLine())
    		{
    			String takeableString = scanner.nextLine();
    			String[] takeableFields = takeableString.split("\\s");
    			if(takeableFields[2].equals("QuestItem"))
    			{
    				Location tempLoc = new Location(Integer.parseInt(takeableFields[0]), Integer.parseInt(takeableFields[1]));
    				QuestItem item = new QuestItem(takeableFields[3], takeableFields[4]);
    				ret.put(tempLoc, item);
    				System.out.println("This is working fine");
    				System.out.println(item.toString());
    				System.out.println(tempLoc.getXPos());
    				System.out.println(tempLoc.getYPos());
    			}
    			else if(takeableFields[2].equals("OneShotItem"))
    			{
    				Location tempLoc = new Location(Integer.parseInt(takeableFields[0]), Integer.parseInt(takeableFields[1]));
    				String stat = scanner.nextLine();
    				String[] statFields = stat.split("\\s");
    				System.out.println(stat);
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]), Integer.parseInt(statFields[8]));
    				OneShotItem item = new OneShotItem(takeableFields[3], takeableFields[4], stats);
    				ret.put(tempLoc, item);
    			}
    			else if(takeableFields[2].equals("UsableItem"))
    			{
    				Location tempLoc = new Location(Integer.parseInt(takeableFields[0]), Integer.parseInt(takeableFields[1]));
    				String stat = scanner.nextLine();
    				String[] statFields = stat.split("\\s");
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]),Integer.parseInt(statFields[8]));
    				UsableItem item = new UsableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), stats);
    				ret.put(tempLoc,item);
    			}
    			else if(takeableFields[2].equals("EquippableItem"))
    			{
    				Location tempLoc = new Location(Integer.parseInt(takeableFields[0]), Integer.parseInt(takeableFields[1]));
    				String stat = scanner.nextLine();
    				String occ = scanner.nextLine();
    				String[] statFields = stat.split("\\s");
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]),Integer.parseInt(statFields[8]));
        			String[] occFields = occ.split("\\s");
        			ArrayList<String> occStrings = new ArrayList<String>();
        			for (String o : occFields)
        			{
        				occStrings.add(o);
        			}
        			
        			int position = Integer.parseInt(takeableFields[6]);
        			EquippableItem item = null;
        			if(position == 0)
        			{
        				item = new EquippableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), 
        						stats, occStrings, EquippableItemPosition.Head, takeableFields[7]);
        			}
        			else if(position == 1)
        			{
        				item = new EquippableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), 
        						stats, occStrings, EquippableItemPosition.Torso, takeableFields[7]);
        			}
        			else if(position == 2)
        			{
        				item = new EquippableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), 
        						stats, occStrings, EquippableItemPosition.LeftArm, takeableFields[7]);
        			}
        			else if (position == 3)
        			{
        				item = new EquippableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), 
        						stats, occStrings, EquippableItemPosition.RightArm, takeableFields[7]);
        			}
        			else if (position == 4)
        			{
        				item = new EquippableItem(takeableFields[3], takeableFields[4], Integer.parseInt(takeableFields[5]), 
        						stats, occStrings, EquippableItemPosition.Legs, takeableFields[7]);
        			}
        			else
        			{
        				//Do nothing
        			}
        			if(item != null)
        			{
        				ret.put(tempLoc,item);
        			}
        			
        		}
    			else
    			{
    				System.out.println("This is just a safe check");
    				System.out.println("There's something wrong with the File's format cause it should not reach here");    			
    			}
    			
    		}
        	
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
    	
    	return ret;
    }
    
    /**
     * File Format
     * --------------------
     * NonTrapItem
     * X Y 
     * NonTrapItem itemName imageID state activatedImageID
     * Exp Life HP MP STR AGI INT HAR MVMSPEED  		// Required Stat
     * itemName1 itemName2 itemName3 ... 	// Required Item's names, separated by space
     * TrapItem
     * X Y 
     * TrapItem itemName imageID state activedImageID
     * @param fileName
     * @return
     */ 
    public static Map<Location, InteractiveItemVisitable> interactiveItemParser(String fileName)
    {
    	Map<Location,InteractiveItemVisitable> ret = null;
    	try
    	{
    		Scanner scanner = new Scanner(new File(fileName));
    		ret = new HashMap<Location,InteractiveItemVisitable>();
    		while(scanner.hasNextLine())
    		{
    			String type = scanner.nextLine();

    			if(type.equals("NonTrapItem"))
    			{
        			String loc = scanner.nextLine();
        			String[] locs = loc.split("\\s");
        			Location newLoc = new Location(Integer.parseInt(locs[0]), Integer.parseInt(locs[1]));
        			String takeableField = scanner.nextLine();
        			System.out.println(takeableField);
        			String[] takeableFields = takeableField.split("\\s");
        	
         			String statString = scanner.nextLine();
        			String itemReq = scanner.nextLine();
        			String[] statFields = statString.split("\\s");
        			String[] itemReqList = itemReq.split("\\s");
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]), Integer.parseInt(statFields[8]));
        			Requirements req = new Requirements(stats, itemReqList);
        			boolean tempState = false;
        			if(takeableFields[3].equals("true"))
        			{
        				tempState = true;
        			}
        			NonTrapItem item = new NonTrapItem(takeableFields[1], takeableFields[2], req, tempState, takeableFields[4]);
        			ret.put(newLoc, item);
        			
    			}
    			else if (type.equals("TrapItem"))
    			{
    				String loc = scanner.nextLine();
        			String[] locs = loc.split("\\s");
        			Location newLoc = new Location(Integer.parseInt(locs[0]), Integer.parseInt(locs[1]));
        			String takeableField = scanner.nextLine();
        			String[] takeableFields = takeableField.split("\\s");

       				boolean state = false;
    				if(takeableFields[3].equals("true"))
    				{
    					state = true;
    				}
    				TrapItem item = new TrapItem(takeableFields[1], takeableFields[2], state, takeableFields[4]);
    				ret.put(newLoc, item);
    			}
    			else
    			{
    				
    				System.out.println("This should not happen");
    			}
    			
    		}
        	
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
    	
    	return ret;
    }
    
    /**
     * Load Images to the Library
     * 
     *  
     * File format for this
     * ------
     * QuestItem itemName imageID
     * OneShotItem itemName imageID 
     * Exp Life HP MP STR AGI INT HAR MVMSPEED	 	// This is the Stat
     * UsableItem itemName imageID price
     * Exp Life HP MP STR AGI INT HAR MVMSPEED   	
     * EquippableItem itemName imageID price ITEMPOSITION EQUIPMENT_TYPE
     * Exp Life HP MP STR AGI INT HAR MVMSPEED
     * occupationName1 occupationName2 ect..
     * ObstacleItem name imageID
     * NonTrapItem name imageID state activated
     * Exp Life HP MP STR AGI INT HAR MVMSPEED
     * occupationName1 occupationName2 ect..
     * TrapItem name imageID state Activated
     * @param fileName
     */
    
    public static void loadingImageLibrary(String fileName)
    {
    	
    	try
    	{
    		Scanner scanner = new Scanner(new File(fileName));
    		while(scanner.hasNextLine())
    		{
    			String takeableString = scanner.nextLine();
    			String[] takeableFields = takeableString.split("\\s");
    			if(takeableFields[0].equals("QuestItem"))
    			{
    				QuestItem item = new QuestItem(takeableFields[1], takeableFields[2]);
    				ItemLibrary.addToLibrary(item, item.getName());
    			}
    			else if(takeableFields[0].equals("OneShotItem"))
    			{
    				String stat = scanner.nextLine();
    				System.out.println("ASDASDASDAS " + stat);
    				String[] statFields = stat.split("\\s");
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]),Integer.parseInt(statFields[8]) );
    				OneShotItem item = new OneShotItem(takeableFields[1], takeableFields[2], stats);
    				ItemLibrary.addToLibrary(item, item.getName());
    			}
    			else if(takeableFields[0].equals("UsableItem"))
    			{
    				String stat = scanner.nextLine();
    				String[] statFields = stat.split("\\s");
    				System.out.println("ASD" +stat);
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]),Integer.parseInt(statFields[8]));
    				UsableItem item = new UsableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), stats);
    				ItemLibrary.addToLibrary(item, item.getName());
    			}
    			else if(takeableFields[0].equals("EquippableItem"))
    			{
    				String stat = scanner.nextLine();
    				String occ = scanner.nextLine();
    				String[] statFields = stat.split("\\s");
    				System.out.println("HELLO" + stat);
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]),Integer.parseInt(statFields[8]));
        			String[] occFields = occ.split("\\s");
        			ArrayList<String> occStrings = new ArrayList<String>();
        			for (String o : occFields)
        			{
        				occStrings.add(o);
        			}
        			
        			int position = Integer.parseInt(takeableFields[4]);
        			EquippableItem item = null;
        			if(position == 0)
        			{
        				item = new EquippableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), 
        						stats, occStrings, EquippableItemPosition.Head, takeableFields[5]);
        			}
        			else if(position == 1)
        			{
        				item = new EquippableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), 
        						stats, occStrings, EquippableItemPosition.Torso, takeableFields[5]);
        			}
        			else if(position == 2)
        			{
        				item = new EquippableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), 
        						stats, occStrings, EquippableItemPosition.LeftArm, takeableFields[5]);
        			}
        			else if (position == 3)
        			{
        				item = new EquippableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), 
        						stats, occStrings, EquippableItemPosition.RightArm, takeableFields[5]);
        			}
        			else if (position == 4)
        			{
        				item = new EquippableItem(takeableFields[1], takeableFields[2], Integer.parseInt(takeableFields[3]), 
        						stats, occStrings, EquippableItemPosition.Legs, takeableFields[5]);
        			}
        			else
        			{
        				//Do nothing
        			}
        			if(item != null)
        			{
        				ItemLibrary.addToLibrary(item, item.getName());
        			}
        			
        		}
    			else if(takeableFields[0].equals("Obstacle"))
    			{
        			ObstacleItem item = new ObstacleItem(takeableFields[1], takeableFields[2]);
        			ItemLibrary.addToLibrary(item, item.getName());
    			}
    			
    			else if(takeableFields[0].equals("NonTrapItem"))
    			{
        			String statString = scanner.nextLine();
        			String itemReq = scanner.nextLine();
        			String[] statFields = statString.split("\\s");
        			String[] itemReqList = itemReq.split("\\s");
        			System.out.println("NonTrap" + statString);
        			Stats stats = new Stats(Integer.parseInt(statFields[0]), Integer.parseInt(statFields[1]), 
        					Integer.parseInt(statFields[2]), Integer.parseInt(statFields[3]), 
        					Integer.parseInt(statFields[4]),Integer.parseInt(statFields[5]),
        					Integer.parseInt(statFields[6]),Integer.parseInt(statFields[7]), Integer.parseInt(statFields[8]));
        			Requirements req = new Requirements(stats, itemReqList);
        			boolean tempState = false;
        			if(takeableFields[3].equals("true"))
        			{
        				tempState = true;
        			}
        			NonTrapItem item = new NonTrapItem(takeableFields[1], takeableFields[2], req, tempState, takeableFields[4]);
        			ItemLibrary.addToLibrary(item, item.getName());
    			}
    			
    			else if(takeableFields[0].equals("TrapItem"))
    			{
    				boolean state = false;
    				if(takeableFields[3].equals("true"))
    				{
    					state = true;
    				}
    				TrapItem item = new TrapItem(takeableFields[1], takeableFields[2], state, takeableFields[4]);
    				ItemLibrary.addToLibrary(item, item.getName());
    			}
    			
    			else
    			{
    				System.out.println("ASDKAJSDASJDLAJDLAKSJD HAHAHAHAH" + takeableFields[0]);
    				System.out.println("This is just a safe check");
    				System.out.println("There's something wrong with the File's format cause it should not reach here");    			
    			}
    			
    		}
        	
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
    }
    
    
    
    public static Map<Location,TakeableItem> parseLocationToItem(String stringName)
    {
    	Map<Location,TakeableItem> map = new HashMap<Location,TakeableItem>();
    	try
    	{
    		
    		Scanner scanner = new Scanner(new File(stringName));
    		while(scanner.hasNext())
    		{
    			String string = scanner.nextLine();
    			String tokens[] = string.split("\\s");
    			Location loc = new Location(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]));
    			if(tokens[2].equals("EquippableItem"))
    			{
    				EquippableItem item = (EquippableItem)ItemLibrary.getFromLibrary(tokens[3]);
    				map.put(loc, item);

    			}
    			else if(tokens[2].equals("QuestItem"))
    			{
    				QuestItem item = (QuestItem)ItemLibrary.getFromLibrary(tokens[3]);
    				map.put(loc, item);
    				System.out.println("STUFF I NEED TO FIX" + map.get(loc).getImageID());
    				System.out.println("STUFFINEEDTOFIX" + map.containsValue("keyQuest"));
    			}
    			else if(tokens[2].equals("OneShotItem"))
    			{
    				OneShotItem item = (OneShotItem)ItemLibrary.getFromLibrary(tokens[3]);
    				map.put(loc, item);
    			}
    			else if(tokens[2].equals("UsableItem"))
    			{
    				UsableItem item = (UsableItem)ItemLibrary.getFromLibrary(tokens[3]);
    				map.put(loc, item);
    			}
    			else
    			{
    				//never happen;
    			}
    		}
    		
    	}
    	catch(FileNotFoundException e)
    	{
    		e.printStackTrace();
    	}
		return map;
    }

}
